***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB34"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.3.4 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property"
global ctrl_work	"mean_votation wcrSR_F_N"
global ctrl_work_b	"mean_votation wcrSR_F_N lcrSR_F_N"
global fe			"charact_agglo"
global fe_iv		"I_charact_agglo_*"
global cluster		"charact_agglo"

// Column 1
		
areg oui instr_dev_mk /// 
	$ctrl_work ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster)	
estimates store RF_dev_work

keep if e(sample)

// Column 2

areg endog_mk instr_dev_mk /// 		
	$ctrl_work ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster)	
estimates store FS_dev_work
test instr_dev_mk
estadd scalar F_fs=r(F)
		
// Column 3
		
ivreg2 oui (endog_mk = instr_dev_mk) ///
	$ctrl_work ///
	$ctrl_base ///
	$fe_iv ///
	if sample_hq00dstr==1, ///
	cluster($cluster) first partial($fe_iv)	
estimates store TSLS_dev_work

// Column 4
		
areg oui instr_dev_mk /// 		
	$ctrl_work_b ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster)	
estimates store RF_dev_work_ctrl

// Column 5

areg endog_mk instr_dev_mk /// 		
	$ctrl_work_b ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster)	
estimates store FS_dev_work_ctrl
test instr_dev_mk
estadd scalar F_fs=r(F)
		
// Column 6
		
ivreg2 oui (endog_mk = instr_dev_mk) ///
	$ctrl_work_b ///
	$ctrl_base ///
	$fe_iv ///
	if sample_hq00dstr==1, ///
	cluster($cluster) first partial($fe_iv)	
estimates store TSLS_dev_work_ctrl

// Labels

la var endog_mk 		"Crime News Exposure ($ \mathtt{CNE} $)"
la var instr_dev_mk 	"[0.1em] HQ $ \mathtt{CPD} $ Deviation ($ \mathtt{\Delta HQC} $)"
la var lcrSR_F_N 		"[0.1em] Local $ \mathtt{CPD} $"
la var wcrSR_F_N 		"[0.1em] Workplace $ \mathtt{CPD} $"
la var mean_votation 	"[0.1em] Past Vote Outcomes"

// Table
	
estout RF_dev_work FS_dev_work TSLS_dev_work RF_dev_work_ctrl FS_dev_work_ctrl TSLS_dev_work_ctrl ///
	using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N r2_a F_fs, lab("Observations" "Adjusted $ R^2 $" "First-stage F-statistic") fmt(0 3 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_mk wcrSR_F_N lcrSR_F_N mean_votation instr_dev_mk) /// 
	order(endog_mk wcrSR_F_N lcrSR_F_N mean_votation instr_dev_mk) ///	
	title(News and voting: Control for crime where people work (commuting)) ///	
	prehead("\begin{table}[!h]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///
	"\\" ///
	"Crime Controls	&\multicolumn{3}{c}{Workplace Crime Prop. Diff.} 	&\multicolumn{3}{c}{(i) Workplace Crime Prop. Diff.}\\" ///
	"					&\multicolumn{3}{c}{ } 									&\multicolumn{3}{c}{(ii) Local Crime Prop. Diff.}\\" ///
	"					\cmidrule(lr){2-4} \cmidrule(lr){5-7} " ///
	"Specification		&\multicolumn{1}{c}{RF}			&\multicolumn{1}{c}{FS}			&\multicolumn{1}{c}{2SLS}		&\multicolumn{1}{c}{RF}		&\multicolumn{1}{c}{FS}		&\multicolumn{1}{c}{2SLS} \\" ///
	"					\cmidrule(lr){2-2} 				\cmidrule(lr){3-4}				\cmidrule(lr){5-5}				\cmidrule(lr){6-7}" ///
	"Dependent Variable &\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes} &\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes} \\" ///
	"					\cmidrule(lr){2-2} 				\cmidrule(lr){3-4}				\cmidrule(lr){5-5}				\cmidrule(lr){6-7}" ///
	"					&\multicolumn{1}{c}{(1)} 	&\multicolumn{1}{c}{(2)}  	&\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)}  	&\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)}\\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at agglomeration level in parentheses. " ///
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " ///
	"Columns (1) to (3) present 2SLS estimation when controlling for workplace Crime Propensity Differential instead of the local one; " ///
	"Columns (4) to (6) when simultaneously controlling for workplace and local Crime Propensity Differential. " ///
	"Columns (1) and (4) present the reduced form estimation; Columns (2) and (5) the first-stage; Columns (3) and (6) the second-stage estimates. " ///
	"All regressions include the full vector of controls of Table \ref{Main_Table2}. " ///
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
